﻿$(document).ready(function () {
    $('#btnedit').click(function () {
        var _flag = $(".account-info-container").attr('id');
        var data = { Id: 1, flag: _flag };
        $.ajax({
            type: "POST",
            url: "/Host/EditView",
            content: "application/json; charset=utf-8",
            dataType: "json",
            data: data,
            success: function (d) {
                $(".account-info-container").html(d.content);
                if (_flag == 0) {
                    $(".account-info-container").attr('id', 1);
                    $("#btnedit").html('<span class="glyphicon glyphicon-ok"></span> Hoàn thành');
                    $("#btncancel").css("visibility", "visible");
                }
                else {
                    $(".account-info-container").attr('id', 0);
                    $("#btnedit").html('<span class="glyphicon glyphicon-edit"></span> Chỉnh sửa thông tin');
                    $("#btncancel").css("visibility", "hidden");
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                alert(xhr.responseText);
            }
        });
    });


    $('#btncancel').click(function () {
        var _flag = $(".account-info-container").attr('id');
        var data = { Id: 1, flag: _flag };
        $.ajax({
            type: "POST",
            url: "/Host/EditView",
            content: "application/json; charset=utf-8",
            dataType: "json",
            data: data,
            success: function (d) {
                $(".account-info-container").html(d.content);

                $(".account-info-container").attr('id', 0);
                $("#btnedit").html('<span class="glyphicon glyphicon-edit"></span> Chỉnh sửa thông tin');
                $("#btncancel").css("visibility", "hidden");

            },
            error: function (xhr, textStatus, errorThrown) {
                alert(xhr.responseText);
            }
        });
    });
});